package cn.main;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
       System.out.println(NumberOfKBetween1AndN_Solution(2593,5));
    }
    
   public static int NumberOfKBetween1AndN_Solution(int n,int m)
    {
        if(n < 1) return 0;
        if(n < 9) return 1;
        
        int high = 0;
        int k = 0;
        int cur = 0;
        int count = 0;
        
        for(int i = 1; (k = n / i) !=0; i *= 10){
            high = k / 10;
            
            count += high * i;
            
            cur = k % 10;
            if(cur > m)
                count += i;
            else if(cur == m)
                count += n - k * i + 1;
        }
        
        return count;   
    }
}